package edu.neusoft.kongfanfei317.yuejian1.activity;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import edu.neusoft.kongfanfei317.yuejian1.R;
import edu.neusoft.kongfanfei317.yuejian1.bean.LoginBean;
import edu.neusoft.kongfanfei317.yuejian1.listener.TListener;

public class MasterBuyActivity extends BaseActivity {
    TextView buy_user,buy_name,buy_price,all_price;
    EditText buy_address,buy_num,buy_time;
    Button buy,check;
    Float num,allprice;
    String foodname,foodprice,buyuser;
    TListener<LoginBean> tListener = new TListener<LoginBean>() {
        @Override
        public void onResponse(LoginBean loginBean) {

        }

        @Override
        public void onFail(String msg) {

        }
    };
    @Override
    void initView() {
        setLayout_file(R.layout.activity_master_buy);
        buy_user=(TextView)findViewById(R.id.buy_user);
        buy_name=(TextView)findViewById(R.id.buy_name);
        buy_price=(TextView)findViewById(R.id.buy_price);
        all_price=(TextView)findViewById(R.id.all_price);
        buy_address=(EditText)findViewById(R.id.buy_address);
        buy_num=(EditText)findViewById(R.id.buy_num);
        buy_time=(EditText)findViewById(R.id.buy_time);
        buy=(Button)findViewById(R.id.buy);
        check=(Button)findViewById(R.id.check);
    }

    @Override
    void initEvent() {
        buy_num.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if(buy_num.getText().toString().equals("")) {
                    showToast("请输入数量");
                }else{

                    Float price = Float.parseFloat(foodprice);
                    Float nums = Float.parseFloat(buy_num.getText().toString());
                    allprice = nums * price;
                    //showToast(allprice.toString());
                    all_price.setText(allprice+"");
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                showToast("下单成功");
            }
        });
      /*  check.setOnClickListener(new View.OnClickListener() {//addtestchangelisten
            @Override
            public void onClick(View view) {
                if (buy_num.getText().toString() != null) {
                    Float price = Float.parseFloat(foodprice);
                    Float nums = Float.parseFloat(buy_num.getText().toString());
                    allprice = nums * price;
                    //showToast(allprice.toString());
                    all_price.setText(allprice.toString());

                }
                else
                    showToast("请填写数量");
            }
        });*/
    }

    @Override
    void initData() {
        Intent intent=getIntent();
        foodname=intent.getStringExtra("foodname");
        foodprice=intent.getStringExtra("foodprice");
        buyuser=intent.getStringExtra("username");
        buyuser=getUser_name();
        buy_name.setText(foodname);
        buy_price.setText(foodprice);
        buy_user.setText(buyuser);
    }
/*
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_buy);
    }*/
}
